#!/bin/bash

# 检查PHP环境
if ! command -v php &> /dev/null; then
    echo "PHP not found, please install PHP first"
    exit 1
fi

# 检查Composer
if ! command -v composer &> /dev/null; then
    echo "Composer not found, please install Composer first"
    exit 1
fi

# 安装依赖
composer install --no-dev

# 创建配置文件
if [ ! -f ".env" ]; then
    cp .env.example .env
    echo "Please configure your .env file"
    exit 1
fi

# 创建目录
mkdir -p runtime/cache
mkdir -p runtime/log
mkdir -p runtime/temp
mkdir -p public/uploads/images
mkdir -p public/uploads/videos
mkdir -p public/uploads/files

# 设置权限
chmod -R 755 runtime
chmod -R 755 public/uploads

# 初始化数据库
php think migrate:run

# 清除缓存
php think clear

echo "Installation completed!" 